package com.sr.examination.user.widget;

import android.app.Activity;
import android.graphics.drawable.ColorDrawable;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.PopupWindow;

import com.sr.examination.R;
import com.tl.commonlibrary.ui.beans.User;


/**
 * 弹窗
 */

public class GenderPop extends PopupWindow implements View.OnClickListener {
    private Activity mContext;

    public GenderPop(Activity context) {
        this.mContext = context;
        init();
    }

    View rootView;

    private void init() {
        setAnimationStyle(R.style.popup_show_Animation);
        // 设置弹出窗体的宽和高
        setHeight(ViewGroup.LayoutParams.WRAP_CONTENT);
        setWidth(ViewGroup.LayoutParams.MATCH_PARENT);
        // 设置弹出窗体可点击
        setFocusable(true);
        setBackgroundDrawable(new ColorDrawable(0x00000000));
        //解决华为手机window被navigationBar挡住
        setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
        rootView = View.inflate(mContext, R.layout.pop_gender, null);
        rootView.findViewById(R.id.manBtn).setOnClickListener(this);
        rootView.findViewById(R.id.womanBtn).setOnClickListener(this);
        rootView.findViewById(R.id.cancelBtn).setOnClickListener(this);
        setContentView(rootView);
        setOnDismissListener(new OnDismissListener() {
            @Override
            public void onDismiss() {
                WindowManager.LayoutParams lp = mContext.getWindow().getAttributes();
                lp.alpha = 1.0f;
                mContext.getWindow().setAttributes(lp);
            }
        });
    }

    @Override
    public void onClick(View v) {
        int id = v.getId();
        switch (id) {
            case R.id.manBtn://收藏
                dismiss();
                if (onGenderListener != null) {
                    onGenderListener.onGender(User.GENDER_MAN, mContext.getString(R.string.gender_man));
                }
                break;
            case R.id.womanBtn://收藏
                dismiss();
                if (onGenderListener != null) {
                    onGenderListener.onGender(User.GENDER_WOMAN, mContext.getString(R.string.gender_woman));
                }
                break;
            case R.id.cancelBtn://查看历史得分
                dismiss();
                break;

        }
    }

    @Override
    public void showAtLocation(View parent, int gravity, int x, int y) {
        super.showAtLocation(parent, gravity, x, y);
        WindowManager.LayoutParams lp = mContext.getWindow().getAttributes();
        lp.alpha = 0.4f;
        mContext.getWindow().setAttributes(lp);
    }

    public OnGenderListener getOnGenderListener() {
        return onGenderListener;
    }

    public void setOnGenderListener(OnGenderListener onMoreListener) {
        this.onGenderListener = onMoreListener;
    }

    private OnGenderListener onGenderListener;

    public interface OnGenderListener {
        void onGender(int gender, String genderName);
    }

}
